package com.hs.srm.common.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @Description 计划塔redis配置, 连接计划塔redis获取3开头物料数据
 * @Author hp
 * @Date 2020-06-11
 */
//@Configuration
public class JHTRedisConfig extends RedisConfig {

    @Value("${spring.redisJHT.database}")
    private int dbIndex;

    @Value("${spring.redisJHT.host}")
    private String host;

    @Value("${spring.redisJHT.port}")
    private int port;

    @Value("${spring.redisJHT.password}")
    private String password;

    @Value("${spring.redisJHT.timeout}")
    private int timeout;

    /**
     * 配置redis连接工厂
     *
     * @return
     */
    @Bean
    public RedisConnectionFactory JHTRedisConnectionFactory() {
        return createRedisConnectionFactory(dbIndex, host, port, password, timeout);
    }

    /**
     * 配置redisTemplate 注入方式使用@Resource(name="") 方式注入
     *
     * @return
     */
    @Bean(name = "JHTRedisTemplate")
    public RedisTemplate jhtRedisTemplate() {
        RedisTemplate template = new RedisTemplate();
        template.setConnectionFactory(JHTRedisConnectionFactory());
        setSerializer(template);
        template.afterPropertiesSet();
        return template;
    }
}
